﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreDB.Extensions
{
    /// <summary>
    /// 单位转换的扩展类（常用）
    /// </summary>
    public static class UnitExtension
    {
        /// <summary>
        /// 从毫米mm转换至英尺Ft
        /// </summary>
        /// <param name="mm"></param>
        /// <returns></returns>
        public static double FT(this double mm)
        {
            return UnitUtils.MM2FT(mm);
        }
        public static double FT(this int mm)
        {
            return ((double)mm).FT();
        }
        /// <summary>
        /// 从英尺Ft转换至毫米mm
        /// </summary>
        /// <param name="ft"></param>
        /// <returns></returns>
        public static double MM(this double ft)
        {
            return UnitUtils.FT2MM(ft);
        }
        public static double MM(this int ft)
        {
            return ((double)ft).MM();
        }
        /// <summary>
        /// 从角度转换至弧度
        /// </summary>
        /// <returns></returns>
        public static double Rad(this double degree)
        {
            return UnitUtils.DEG2RAD(degree);
        }
        public static double Rad(this int degree)
        {
            return ((double)degree).Rad();
        }
        /// <summary>
        /// 从弧度转换成为角度
        /// </summary>
        /// <param name="radian"></param>
        /// <returns></returns>
        public static double Degree(this double radian)
        {
            return UnitUtils.RAD2DEG(radian);
        }
        public static double Degree(this int radian)
        {
            return ((double)radian).Degree();
        }

    }

    /// <summary>
    /// 单位转换有非常多类型的需求，这里定义一个工具类
    /// </summary>
    public static class UnitUtils
    {
        public static double FT2MM(double ft)
        {
            return ft *= 304.8;
        }
        public static double FT2CM(double ft)
        {
            return ft *= 30.48;
        }
        public static double FT2M(double ft)
        {
            return ft *= 0.3048;
        }
        public static double MM2FT(double mm)
        {
            return mm /= 304.8;
        }
        public static double CM2FT(double cm)
        {
            return cm /= 30.48;
        }
        public static double M2FT(double m)
        {
            return m /= 0.3048;
        }

        /// <summary>
        /// Degree to radian
        /// 角度 => 弧度 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double DEG2RAD(double value)
        {
            return value * Math.PI / 180;
        }
        /// <summary>
        /// Radian to degree
        /// 弧度 => 角度
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double RAD2DEG(double value)
        {
            return value * 180 / Math.PI;
        }
    }
}
